
#include "keywords.h"

Keywords::Keywords( void ) {
  return;
}

Keywords::~Keywords( void ) {
  getKeywords().clear();
  return;
}

std::string Keywords::getKeywordList( std::string glue ) { // public
  return Regex::implode( glue, getKeywords() );
}

void Keywords::addKeyword( const std::string& keyword ) { // public
  getKeywords().insert( keyword );
  return;
}

void Keywords::removeKeyword( const std::string& keyword ) { // public
  getKeywords().erase( keyword );
  return;
}

bool Keywords::matchesKeyword( const std::string& search ) { // public
  for ( std::set<std::string>::iterator it = getKeywords().begin(); it != getKeywords().end(); ++it ) {
    if ( it->find( search ) == 0 ) {
      return true;
    }
  }
  return false;
}

std::string Keywords::serializeKeywords( void ) { // public
  return Regex::implode( "|", getKeywords() );
}

void Keywords::unserializeKeywords( const std::string& serialization ) { // public
  std::vector<std::string> keywords = Regex::explode( "|", serialization );
  for ( std::vector<std::string>::iterator it = keywords.begin(); it != keywords.end(); ++it ) {
    addKeyword( *it );
  }
  return;
}

